package com.nanbei.list;


import org.junit.Test;
import org.springframework.util.StopWatch;

import java.util.LinkedList;

public class DynamicArrayTest {

    @Test
    public void testArray(){
        DynamicArray dynamicArray = new DynamicArray();
        dynamicArray.addLast(1);
        dynamicArray.addLast(2);
        dynamicArray.addLast(3);
        dynamicArray.addLast(4);
        dynamicArray.addLast(5);
        dynamicArray.addLast(6);
        dynamicArray.addLast(7);

        dynamicArray.add(7,8);

        LinkedList<Integer> linkedList = new LinkedList<>();
    }

    @Test
    public void test2(){
        int row = 1000000, list = 14;
        int[][] arrays = new int[row][list];

        StopWatch stopWatch = new StopWatch();
        stopWatch.start("ij");
        ij(arrays,row,list);
        stopWatch.stop();
        stopWatch.start("ji");
        ji(arrays,row,list);
        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());

    }

    public static void ij(int[][] arrays,int row,int list){
        long sum = 0L;
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < list; j++) {
                sum += arrays[i][j];
            }
        }
        System.out.println(sum);
    }

    public static void ji(int[][] arrays,int row,int list){
        long sum = 0L;
        for (int j = 0; j < list; j++) {
            for (int i = 0; i < row; i++) {
                sum += arrays[i][j];
            }
        }
        System.out.println(sum);
    }

}
